<%@ page import="com.lms.pojo.BorrowRecord" %>
<%@ page import="java.util.List" %>
<%@ page import="com.lms.mapper.BorrowRecordDAO" %>
<%@ page import="com.lms.utils.BorrowRecordDisplay" %>
<%@ page import="com.lms.mapper.BorrowRecordFilter" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%--
  Created by IntelliJ IDEA.
  User: 24534
  Date: 2023/6/3
  Time: 22:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>借阅信息管理</title>
    <link rel="stylesheet" type="text/css" href="css/borrowRecord.css">
</head>
<body>
<%@ include file="sidebar.jsp" %>

<%
    // Create a new instance of BorrowRecordFilter
    BorrowRecordFilter filter = new BorrowRecordFilter();

// Retrieve the form data from the request parameters
    String recordIDStr = request.getParameter("recordID");
    String userIDStr = request.getParameter("userID");
    String bookIDStr = request.getParameter("bookID");
    String borrowDateStartStr = request.getParameter("borrowDateStart");
    String borrowDateEndStr = request.getParameter("borrowDateEnd");
    String returnDateStartStr = request.getParameter("returnDateStart");
    String returnDateEndStr = request.getParameter("returnDateEnd");
    String actualReturnDateStartStr = request.getParameter("actualReturnDateStart");
    String actualReturnDateEndStr = request.getParameter("actualReturnDateEnd");

    if (recordIDStr != null && !recordIDStr.isEmpty())
        filter.setRecordID(Integer.parseInt(recordIDStr));
    if (userIDStr != null && !userIDStr.isEmpty())
        filter.setUserID(Integer.parseInt(userIDStr));
    if (bookIDStr != null && !bookIDStr.isEmpty())
        filter.setBookID(Integer.parseInt(bookIDStr));

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    try {

        if (borrowDateStartStr != null && !borrowDateStartStr.isEmpty())
            filter.setBorrowDateStart(format.parse(borrowDateStartStr));
        if (borrowDateEndStr != null && !borrowDateEndStr.isEmpty())
            filter.setBorrowDateEnd(format.parse(borrowDateEndStr));
        if (returnDateStartStr != null && !returnDateStartStr.isEmpty())
            filter.setReturnDateStart(format.parse(returnDateStartStr));
        if (returnDateEndStr != null && !returnDateEndStr.isEmpty())
            filter.setReturnDateEnd(format.parse(returnDateEndStr));
        if (actualReturnDateStartStr != null && !actualReturnDateStartStr.isEmpty())
            filter.setActualReturnDateStart(format.parse(actualReturnDateStartStr));
        if (actualReturnDateEndStr != null && !actualReturnDateEndStr.isEmpty())
            filter.setActualReturnDateEnd(format.parse(actualReturnDateEndStr));

    } catch (Exception e) {
        e.printStackTrace();
    }

%>

<form action="borrowRecord.jsp" method="GET" style="display: inline">
    <label>记录ID：</label>
    <input type="text" name="recordID" value="<%= recordIDStr==null?"":recordIDStr%>">
    <br>
    <label>用户ID：</label>
    <input type="text" name="userID" value="<%= userIDStr==null?"":userIDStr%>">
    <br>
    <label>图书ID：</label>
    <input type="text" name="bookID" value="<%= bookIDStr==null?"":bookIDStr%>">
    <br>
    <label>借阅日期范围：</label>
    <input type="date" name="borrowDateStart" value="<%= borrowDateStartStr%>"> - <input type="date"
                                                                                         name="borrowDateEnd"
                                                                                         value="<%= borrowDateEndStr%>">
    <br>
    <label>归还日期范围：</label>
    <input type="date" name="returnDateStart" value="<%= returnDateStartStr%>"> - <input type="date"
                                                                                         name="returnDateEnd"
                                                                                         value="<%= returnDateEndStr%>">
    <br>
    <label>实际归还日期范围：</label>
    <input type="date" name="actualReturnDateStart" value="<%= actualReturnDateStartStr%>"> - <input type="date"
                                                                                                     name="actualReturnDateEnd"
                                                                                                     value="<%= actualReturnDateEndStr%>">
    <br>
    <input type="submit" value="筛选">
</form>

<h2>借阅信息表</h2>
<%
    BorrowRecordDAO dao = new BorrowRecordDAO();
    List<BorrowRecord> borrowRecordList = dao.findByFilter(1, 100, filter);
    BorrowRecordDisplay borrowRecordTools = new BorrowRecordDisplay();
%>


<a href="borrowRecordAdd.jsp">添加</a>
<table>
    <tr>
        <th>Record ID</th>
        <th>User ID</th>
        <th>Book ID</th>
        <th>借阅时间</th>
        <th>指定归还时间</th>
        <th>实际归还时间</th>
        <th>操作</th>
    </tr>
    <% for (BorrowRecord borrowRecord : borrowRecordList) { %>
    <tr>
        <td><%= borrowRecord.getRecordID() %>
        </td>
        <td><%= borrowRecordTools.userIdToString(borrowRecord.getUserID()) %>
        </td>
        <td><%= borrowRecordTools.bookIDToString(borrowRecord.getBookID()) %>
        </td>
        <td><%= borrowRecord.getBorrowDate().toString() %>
        </td>
        <td><%= borrowRecord.getReturnDate().toString() %>
        </td>
        <td><%= borrowRecord.getActualReturnDate() == null ? "未归还" : borrowRecord.getActualReturnDate().toString() %>
        </td>
        <td>
            <a href="deleteBorrowRecord?recordID=<%=borrowRecord.getRecordID()%>"
               onclick="return confirm('确定要删除吗？')">删除</a>
            <a href="borrowRecordModify.jsp?recordID=<%=borrowRecord.getRecordID()%>">修改</a>
        </td>
    </tr>
    <% } %>
</table>

s
</body>
</html>

</body>
</html>
